package com.yanjiali.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yanjiali.entity.SettingContentUser;
import com.yanjiali.mapper.SettingContentUserMapper;
import com.yanjiali.service.SettingContentUserService;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

/**
* @Package: com.yanjiali.service.impl
* @Author: yanjiali
* @Created: 2025/5/1 11:09
*/
@Service
public class SettingContentUserServiceImpl extends ServiceImpl<SettingContentUserMapper, SettingContentUser> implements SettingContentUserService {

    @Override
    public boolean getUserSettingContentStatus(Long settingContentId) {
        String userId = "";
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if(authentication != null) {
            userId = authentication.getPrincipal().toString();
        }else {
            throw new RuntimeException("用户未登录，无法获取对应设置状态");
        }
        LambdaQueryWrapper<SettingContentUser> lqw = new LambdaQueryWrapper<>();
        lqw
                .eq(SettingContentUser::getSetContentId, settingContentId)
                .eq(SettingContentUser::getUid, userId);
        SettingContentUser settingContentUser = getOne(lqw);
        if(settingContentUser == null) {  //TODO 说明当前用户还没有设置过，默认关闭
            return false;
        }

        return settingContentUser.getStatus() == 1; //返回对应的状态
    }
}
